package com.loongtech.bi.advertisment.controller;

import com.loongtech.bi.advertisment.model.AdvWarningInputData;
import com.loongtech.bi.advertisment.service.PayUserService;
import com.loongtech.bi.support.Session;
import com.loongtech.core.util.Time;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 
 * ClassName: AdvWarnInputAction
 * 
 * @Description: 积分墙统计
 * @author liuchen
 * @date 2017-7-31 下午2:10:12
 */
@Controller("advWarnInputAction")
@Scope("view")
public class AdvWarnInputAction extends BaseAdvAction {

	private String dateRadio = "1"; // 切换的天数：1=昨天。7=近7天。15=近15天。30=近30天，0=自选时间

	private Date dateStart = new Date(Time.getBeginningOfDay(Time.currentTime() - 0)); // 自选时间：开始时间
	private Date dateEnd = new Date(Time.getBeginningOfDay(Time.currentTime() - 0)); // 自选时间：结束时间

	private List<AdvWarningInputData> warningDatas;

	private static final long serialVersionUID = 1L;

	@Resource(name = "payUserService")
	private PayUserService payUserService;

	@Resource
	Session session;

	@PostConstruct
	public void init() {
		search();
	}

	public void search() {
		warningDatas = new ArrayList<AdvWarningInputData>();
		try {
			String startDay = Time.getDateStr(
					new Date(Time.getBeginningOfDay(("-1".equals(dateRadio) ? dateStart : new Date(Time
							.getBeginningOfDay(Time.currentTime() - (Integer.parseInt(dateRadio)) * Time.DAY)))
							.getTime()))); // 开始时间
			String endDay = Time.getDateStr(
					new Date(Time.getBeginningOfDay(("-1".equals(dateRadio) ? dateEnd : new Date(Time
							.getBeginningOfDay(Time.currentTime()))).getTime()))); // 结束时间
			warningDatas = payUserService.getListWarningInputData(startDay, endDay);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public String getDateRadio() {
		return dateRadio;
	}

	public void setDateRadio(String dateRadio) {
		this.dateRadio = dateRadio;
	}

	public Date getDateStart() {
		return dateStart;
	}

	public void setDateStart(Date dateStart) {
		this.dateStart = dateStart;
	}

	public Date getDateEnd() {
		return dateEnd;
	}

	public void setDateEnd(Date dateEnd) {
		this.dateEnd = dateEnd;
	}

	public List<AdvWarningInputData> getWarningDatas() {
		return warningDatas;
	}

	public void setWarningDatas(List<AdvWarningInputData> warningDatas) {
		this.warningDatas = warningDatas;
	}
}
